<script type="text/javascript">

    function onCheckClick(ckContent)
    {
        if(ckContent.checked)
            ckContent.value="true";
        else
            ckContent.value="false"
        if(ckContent.name=="ckFocusContent")
        {
            //var url = "<?php echo url_for("other/focus"); ?>" + "?random=" +  Math.random() + "&catalogId=1000&contentTypeId=1000";
            //var focusId = window.showModalDialog(url,null,"dialogWidth:800px;dialogHeight:400px;help:0;status:0;scroll:1;center:1;resizeable:off;");
            //if(focusId != null)
              //$("#txtHideFocusId").val(focusId);
            if(ckContent.checked)
                $("#trFocus").css("display","block");
            else
                $("#trFocus").css("display","none");
        }
    }

    var focusCheck = "<?php echo $focusCheck;?>";
    var recommendCheck = "<?php echo $recommendCheck;?>";
    var isOnTop = "<?php echo $isOnTop;?>";
    var relatedVideo = "<?php echo $relatedVideo;?>" + ";";

    var currentTab = "video";
    var orderStr = "";
    function onRelatedCheckClick(ckRelated, relatedType)
    {
        if(ckRelated != null)
        {
            var tempValue = ckRelated.name ;//+ "," + ckRelated.value
            switch(relatedType)
            {
                case "video":
                   if(ckRelated.checked)
                        relatedVideo += tempValue + ";";
                   else
                        relatedVideo = relatedVideo.replace(tempValue + ";","");
                   break;
            }
        }
    }

    function onSubmit(submitType)
    {
        //去掉首部的 ";";
        if(relatedVideo.indexOf(";") == 0)
            relatedVideo = relatedVideo.substr(1);

        $("#txtHideRelatedVideo").val(relatedVideo.substr(0,relatedVideo.length-1));
        switch(submitType)
        {
            case "edit":
               $("#txtSubmitType").val("edit");
               break;
            case "publish":
               $("#txtSubmitType").val("publish");
               break;
        }
        //return true;
    }

    function onSearch()
    {
        if($.trim($("#txtSearch").val()) == "")
        {
            alert("请输入 Tag 值。");
            return ;
        }
        $("#btnSearch").attr("disabled",true);
        var onSearchingMessage = "正在搜索......";
        $("#divListVideo").html(onSearchingMessage);
        var random = Math.random();
        var searchArray = $.trim($("#txtSearch").val()).split(/,|，/);
        var whereStr = "";

        for(var i = 0 ; i < searchArray.length; i++)
        {
            if(i == 0)
                whereStr = "(tag like '%" + searchArray[i] + "%'";
            else
                whereStr += " or " + "tag like '%" + searchArray[i] + "%'";
        }
        if(relatedVideo != ";")
            whereStr += " or video_id in" + getSqlStr(relatedVideo);
        whereStr +=  ") and video_id !=<?php echo $sf_request->getParameter("content");?>";
        whereStr = encodeURI(whereStr);
        $.ajax({url:"<?php echo url_for("other/jQuery");?>",data:"random=" + random +"&submitFlag=relatedSearch&whereStr=" + whereStr +"&searchType=" + currentTab ,success: onSuccessSearch,error:onErrorSearch})
    }

    function onSuccessSearch(oMessage)
    {
        switch(currentTab)
        {
            case "video":
               //alert(oMessage);
               $("#divListVideo").html(oMessage);
               break;
        }

        $("#btnSearch").attr("disabled",false);
    }

    function onErrorSearch(x, e)
    {
        alert(x.responseText);
        $("#btnSearch").attr("disabled",false);
    }

    function setRelatedCheck(relatedType)
    {
        var relatedIdStr = "";
        var tableName = "";
        switch(relatedType)
        {
            case "news":
                relatedIdStr= relatedNews;
                break;
            case "photo":
                relatedIdStr= relatedPhoto;
                break;
            case "video":
                relatedIdStr= relatedVideo;
                break;
        }
        if(relatedIdStr != "")
        {
            relatedIdStr = relatedIdStr.substr(0,relatedIdStr.length-1);
            var relatedArray = relatedIdStr.split(";");
            for(var i = 0 ; i < relatedArray.length; i++)
                $("#" + relatedType + relatedArray[i]).attr("checked",true);
        }
    }

    function getSqlStr(sourceStr)
    {
        var whereStr = "";
        sourceStr = sourceStr.substr(0,sourceStr.length-1);
        if(sourceStr != "")
            sourceStr = "(" + sourceStr.replace(";",",") + ")";
        return sourceStr;
    }
</script>
<script type="text/javascript" src="/js/flowplayer-3.2.4.min.js"></script>
<form action="<?php echo url_for('video/edit?content='.$video->getVideoId()); ?>" method="post" enctype="multipart/form-data">
<table width="795" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
    <td height="22">视频修改：</td>
    <td colspan="4" align="right" valign="middle" style="padding-right:300px"><input name="btnEdit" type="submit"  value="保 存" onclick="onSubmit('edit')" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="btnBack" type="button" value="取 消" onclick="history.go(-1);" /><input name="btnPublish" type="submit" value="发 布" onclick="onSubmit('publish')" style="display:none;" /></td>
</tr>
<tr>
    <td height="22" colspan="5" valign="top">栏目：
        <label><?php
        @include_component("other", "catalog", array('selectedId' => $video->getCatalogId()));
        ?>
        </label></td>
</tr>
<tr>
    <td height="22" colspan="5" valign="top">视频类别：
        <label>
        <?php
                @include_component("other", "contentCatalog", array('contentTypeId' => '1001', 'selectedId' => $video->getSubCatalogId()));
        ?>
        </label></td>
</tr>
<tr>
    <td height="22" colspan="5" valign="top">文档属性：推荐
        <input id="ckRecommendContent" type="checkbox" name="ckRecommendContent" onclick="onCheckClick(this)"/>&nbsp;&nbsp;&nbsp;
        焦点
        <input id="ckFocusContent" type="checkbox" name="ckFocusContent" onclick="onCheckClick(this)"/>&nbsp;&nbsp;&nbsp;
        置顶
        <input id="ckTop" type="checkbox" name="ckTop" onclick="onCheckClick(this)"/>
        &nbsp;&nbsp;</td>
</tr>
<tr>
    <td height="19" colspan="5">
        <div style="display:none;" id="trFocus">
        <?php echo include_component("other", "focus", array('focusId' => $focusId)); ?>    </div>
    </td>
</tr>
<tr>
    <td height="22" colspan="5" valign="top"><label>
        缩略图：
        <input type="text" id="Txt1" name="Txt1" value="<?php echo $video->getSnapshotBig(); ?>"/><input type="button"
                                                                                                         value="浏览"
                                                                                                         onclick="getFileUrlFromCKFinder('Txt1','Img1')"/>
    </label></td>
</tr>
<tr>
    <td colspan="3"  height="160px"><input type="hidden" value="1" id="Hid1" name="Hid1"> <img id="Img1" src="<?php echo $video->getSnapshotBig(); ?>"  width="184" height="138" alt="184X138"/>
    </td>
    <td width="62">&nbsp;</td>
    <td width="139">&nbsp;</td>
</tr>
<tr>
    <td width="501" height="1"></td>
    <td width="37"></td>
    <td width="56"></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td height="22" colspan="5" valign="top">标&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题：
        <label>
            <input name="title" type="text" size="28" value="<?php echo $video->getTitle(); ?>" maxlength="28"/>
            (28字以内) </label></td>
</tr>
<tr>
    <td height="22" colspan="5" valign="top">作&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;者：
      <input name="artist" type="text" value="<?php echo $video->getArtist(); ?>" size="20" maxlength="100" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;来源：
      <input name="source" type="text" value="<?php echo $video->getSource(); ?>" size="20" maxlength="100" />
    </td>
</tr>
<tr>
    <td colspan="5" valign="top">
        <table width="90%" border="0" cellspacing="0" cellpadding="0">
			  <tr>
				<td width="62px" height="25px">TAG标签：</td>
                <td><input class="focusText" type="text" name="tag" onkeyup='$("#txtSearch").val(this.value);' size="20" value="<?php echo $video->getTag(); ?>"/></td>
				<td rowspan="2">多个关键字和TAG标签，请以“，”分隔</td>
			  </tr>
			  <tr>
				<td height="25px" align="right">关键字：</td>
                <td><input class="focusText" name="keyword" type="text" value="<?php echo $video->getKeyword(); ?>" size="20" /></td>
			  </tr>
			</table>
       </td>
   </tr>
<tr>
            <td height="30" colspan="2" valign="middle">所属视频组：
                <select name="sVedioGroupId" id="sVedioGroupId">
                    <?php echo $videoGroupIdHtml;?>
                </select>
            </td>
            <td width="92">&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
   </tr>
<tr>
    <td height="22" colspan="5" valign="top">视频上传：
        <input name="button3" type="button" value="视频库" onclick="getFileUrlFromCKFinder('Txt3','Img3','video')"/>
        <input id="Txt3" name="Txt3" type="text" value="<?php echo $video->getLink(); ?>" size="20" maxlength="10"
               onchange="changeVideo();"/>
    </td>
</tr>
<tr>
    <td height="22" colspan="5" valign="top">视频预览：</td>
</tr>
<tr>
    <td height="319" colspan="4" valign="top">
        <!--        <input type="hidden" value="1" id="Hid3" name="Hid3">-->
        <!--        <img id="Img3" src="-->
        <!--" alt="600X300" width="600" height="300"/>-->

        <!--        <div class='vod_flash'>-->

        <!--        </div>-->

        <div style="width:600px;height:300px;" id="player"></div>
    </td>
    <td>&nbsp;</td>
</tr>
<tr>
    <td height="22" valign="top">是否审核：
        <?php echo $video->getStatus()->getName(); ?>
        <label>&nbsp;&nbsp;时长：
            <input name="duration" type="text" maxlength="8" value="<?php echo substr($video->getDuration(), 0, 8); ?>"
                   size="10"/>
        </label></td>
    <td colspan="4" valign="top">发布时间：
        <label>
            <input name="nowtime" type="text"
                   value="<?php echo date('Y-m-d  H:i:s', strtotime($video->getPublish_time())); ?>"/>
        </label></td>
</tr>


<tr>
    <td height="22" colspan="5" valign="top">点&nbsp;&nbsp;击&nbsp;&nbsp;率：
        <?php echo $video->getHitI();  ?>
<!--        <input name="hit" readonly="readonly" type="text" size="10" value="--><?php //echo $video->getHitI();  ?><!--"/>-->
        &nbsp;&nbsp;&nbsp;点击调整：
        <input name="hitMark" type="text" size="10" value="<?php echo $video->getHitMaskI(); ?>"/></td>
</tr>
<tr>
    <td height="22" colspan="5" valign="top">内容简介：</td>
</tr>
<tr>
    <td height="55" colspan="5" valign="top"><label>
        <textarea name="brief" cols="70" rows="4"><?php echo $video->getBrief(); ?></textarea>
    </label></td>
</tr>
<tr>
     <td colspan="5">
        <table border="0">
            <tr>
                <td align="right" valign="bottom" style="height:40px;">相关搜索：</td>
              <td valign="bottom"><input type="text" name="txtSearch" id="txtSearch" value="<?php echo $video->getTag();?>">&nbsp;&nbsp;<input type="button" id="btnSearch" value="搜 索" onclick="onSearch()">&nbsp;(请输入 Tag 值，多个Tag值，请以逗号“，”分隔)</td>
            </tr>
        </table>
    </td>
  </tr>
  <tr>
    <td colspan="5">
	   <table height="100%" width="100%" cellSpacing="0" cellPadding="0" style="width:930px;">
			<tr height="25px" style="display:none;">
				<td style="padding-left:10px">
					<table style="height: 22px;" cellSpacing="0" cellPadding="0" border="0">
						<tr valign="bottom">
							<td vAlign="bottom" style="FONT-SIZE: 9pt"><span class="tab tabOn" tabIndex="0" id="tabNews" tabID="tab0" onclick="onTabClick('tabNews')">相关新闻</span><span class="tab" tabIndex="1" tabID="tab2" id="tabVideo" onclick="onTabClick('tabVideo')">相关视频</span><span class="tab" tabIndex="2" tabID="tab2" id="tabPhoto" onclick="onTabClick('tabPhoto')">相关图片</span></td>
						</tr>
					</table>
				</td>
			</tr>
            <tr>
				<td style="padding-left:5px">
                    <div class="tab" id="divVideo">
                        <div class="lists" id="divListVideo">
                            <?php
                                    if($relatedVideo != "")
                                        @include_component("news","getSearchByTag",array("searchType"=>"video","recordCount"=>20,"whereStr"=>"video_id in(".$relatedVideo.")","isEdit"=>"true","tag"=>$video->getTag(),"notInWhereStr"=>"video_id not in(".$relatedVideo.",".$video->getVideoId().")"));
                                    else
                                        echo "在“相关搜索”文本框中，输入相应的 Tag 值，点击“搜索”按钮，即可找到相关的 视频 信息。";//@include_component("news","getSearchByTag",array("searchType"=>"video","recordCount"=>20));
                             ?>
                        </div>
                    </div>
                </td>
            </tr>
</table>
	</td>
  </tr>
<tr>
    <td align="center" colspan="5" style="height:50px;"><input name="btnEdit" type="submit" id="btnEdit" value="保 存" onclick="onSubmit('edit')" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="btnBack" type="button" value="取 消" onclick="history.go(-1);" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="btnPublish" type="submit" id="btnPublish" value="发 布" onclick="onSubmit('publish')" style="display:none;" /></td>
</tr>
<tr>
    <td height="32">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
</tr>
</table>
<input name="txtHideRelatedVideo" type="hidden" id="txtHideRelatedVideo" />
<input name="txtSubmitType" value="add" type="hidden" id="txtSubmitType" />
<input type="hidden" name="videoEdit" id="videoEdit" value="2"/>
</form>
<script>
    function changeVideo() {
        alert("video link changed");
        //        var videoLink = document.getElementById("Txt3").value;
        //        $f("player").play(videoLink);
    }

    $(document).ready(function(){
        var videoLink = document.getElementById("Txt3").value;
        $f("player").play(videoLink);
    });
    setRelatedCheck("video");
    if(recommendCheck == "true")
           $("#ckRecommendContent").attr("checked",true);
        if(focusCheck == "true")
        {
            $("#trFocus").css("display","block");
            $("#ckFocusContent").attr("checked",true);
        }
        if(isOnTop == "true")
            $("#ckTop").attr("checked",true);

        if($.trim($("#hitMark").val()) == "")
           $("#hitMark").val("<?php echo $video->getHitI();?>")
    flowplayer('player', '/js/flowplayer-3.2.5.swf');

</script>
